package org.linlinjava.litemall.db.service.marketing_manage;

import org.linlinjava.litemall.db.dao.marketing_manage.MarketingDeductionMapper;
import org.linlinjava.litemall.db.vo.marketing_manager.DeductionOptTypeEnum;
import org.linlinjava.litemall.db.vo.marketing_manager.DeductionStaticDataInfo;
import org.linlinjava.litemall.db.vo.marketing_manager.DeductionTypeAmountData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author houzb
 * @Description
 * @create 2021-08-30 18:41
 */
@Service
@Transactional
public class AgedmallMarketingDeductionService {
    @Autowired
    private MarketingDeductionMapper marketingDeductionMapper;

    /**
     * 获抵扣金统计的金额数据信息
     * @param params
     * @return
     */
    public DeductionStaticDataInfo getMarketingDeductionStaticDataInfo(Map<String, Object> params) {
        List<DeductionTypeAmountData> typeAmountDataList = marketingDeductionMapper.getDisAndUseStaticDeductionAmount(params);
        double userHasTotal = marketingDeductionMapper.getUserHasTotalDeductionAmount(params);
        DeductionStaticDataInfo dataInfo = new DeductionStaticDataInfo();
        dataInfo.setCouldUseTotal(userHasTotal);
        for(DeductionTypeAmountData typeAmountData:typeAmountDataList) {
            String type = typeAmountData.getType();
            if(DeductionOptTypeEnum.GET.getType().equals(type)) {
                 dataInfo.setCumulativeDisTotal(typeAmountData.getDeductionAmount());
            }else if(DeductionOptTypeEnum.USE.getType().equals(type)) {
                dataInfo.setCumulativeUseTotal(typeAmountData.getDeductionAmount());
            }
        }
        return dataInfo;
    }
}
